// functionPage/components/zts-news/zts-news.js
import throttle from '../../../utils/throttle.js';
// 事件类型：00点赞、01评论、02回复、03提问、04回答提问、05设为优秀、06置顶、07精华
// 01=ft测试点评论、02=ft测试路线评论、03=nfc测试点评论、04=nfc测试路线评论、09=通告评论、12=经验评论、13=日记评论 14=营业厅详情评论
// 01=ft测试点讨论点赞、02=ft测试路线讨论点赞、03=nfc测试点讨论点赞、04=nfc测试路线讨论点赞、05=营业厅留言点赞、06=租车留言点赞、07=住宿留言点赞、08=通告点赞、09=通告讨论点赞、10=问答点赞、11=问答回答点赞、12=经验点赞、13=日记点赞  14=ft测试点点赞、15=ft测试路线点赞、16=nfc测试点点赞、17=nfc测试路线点赞 18=经验讨论点赞
const pathArray = [
    {
        type: '00',
        childen: [
            {
                type: '01',
                path: '/pages/homePageInfo/ftInfo/ftInfo',
            },
            {
                type: '02',
                path: '/pages/homePageInfo/ftRouteInfo/ftRouteInfo',
            },
            {
                type: '03',
                path: '/pages/homePageInfo/nfcInfo/nfcInfo',
            },
            {
                type: '04',
                path: '/pages/homePageInfo/nfcRouteInfo/nfcRouteInfo',
            },
            {
                type: '08',
                path: '/pages/notice/projectNotice/projectNotice',
            },
            {
                type: '09',
                path: '/pages/notice/projectNotice/projectNotice',
            },
            {
                type: '10',
                path:
                    '/pages/notice/projectTeam/interactiveQuestionAndAnswer/interactiveQuestionAndAnswer',
            },
            {
                type: '11',
                path:
                    '/pages/notice/projectTeam/interactiveQuestionAndAnswer/interactiveQuestionAndAnswer',
            },
            {
                type: '12',
                path: '/functionPage/pages/experienceDetail/experienceDetail',
            },
            {
                type: '14',
                path: '/pages/homePageInfo/ftInfo/ftInfo',
            },
            {
                type: '15',
                path: '/pages/homePageInfo/ftRouteInfo/ftRouteInfo',
            },
            {
                type: '16',
                path: '/pages/homePageInfo/nfcInfo/nfcInfo',
            },
            {
                type: '17',
                path: '/pages/homePageInfo/nfcRouteInfo/nfcRouteInfo',
            },
            {
                type: '18',
                path: '/functionPage/pages/experienceDetail/experienceDetail',
            },
            {
                type: '19',
                path: '/functionPage/pages/cszxDetail/cszxDetail?type=01',
            },
            {
                type: '20',
                path: '/functionPage/pages/cszxDetail/cszxDetail?type=02',
            },
            {
                type: '21',
                path: '/functionPage/pages/cszxDetail/cszxDetail?type=03',
            },
            {
                type: '22',
                path: '/functionPage/pages/cszxDetail/cszxDetail?type=04',
            },
            {
                type: '27',
                path: '/functionPage/pages/minePage/checkInIfo/checkInIfo',
            },
        ],
    },
    {
        type: '01',
        childen: [
            {
                type: '01',
                path: '/pages/homePageInfo/ftInfo/ftInfo',
            },
            {
                type: '02',
                path: '/pages/homePageInfo/ftRouteInfo/ftRouteInfo',
            },
            {
                type: '03',
                path: '/pages/homePageInfo/nfcInfo/nfcInfo',
            },
            {
                type: '04',
                path: '/pages/homePageInfo/nfcRouteInfo/nfcRouteInfo',
            },
            {
                type: '09',
                path: '/pages/notice/projectNotice/projectNotice',
            },
            {
                type: '12',
                path: '/functionPage/pages/experienceDetail/experienceDetail',
            },
            {
                type: '19',
                path: '/functionPage/pages/cszxDetail/cszxDetail?type=01',
            },
            {
                type: '20',
                path: '/functionPage/pages/cszxDetail/cszxDetail?type=02',
            },
            {
                type: '21',
                path: '/functionPage/pages/cszxDetail/cszxDetail?type=03',
            },
            {
                type: '22',
                path: '/functionPage/pages/cszxDetail/cszxDetail?type=04',
            },
            {
                type: '27',
                path: '/functionPage/pages/minePage/checkInIfo/checkInIfo',
            },
        ],
    },
    {
        type: '02',
        childen: [
            {
                type: '01',
                path: '/pages/homePageInfo/ftInfo/ftInfo',
            },
            {
                type: '02',
                path: '/pages/homePageInfo/ftRouteInfo/ftRouteInfo',
            },
            {
                type: '03',
                path: '/pages/homePageInfo/nfcInfo/nfcInfo',
            },
            {
                type: '04',
                path: '/pages/homePageInfo/nfcRouteInfo/nfcRouteInfo',
            },
            {
                type: '09',
                path: '/pages/notice/projectNotice/projectNotice',
            },
            {
                type: '12',
                path: '/functionPage/pages/experienceDetail/experienceDetail',
            },
            {
                type: '27',
                path: '/functionPage/pages/minePage/checkInIfo/checkInIfo',
            },
        ],
    },
    {
        type: '03',
        path:
            '/pages/notice/projectTeam/interactiveQuestionAndAnswer/interactiveQuestionAndAnswer',
    },
    {
        type: '04',
        path:
            '/pages/notice/projectTeam/interactiveQuestionAndAnswer/interactiveQuestionAndAnswer',
    },
    {
        type: '05',
        path:
            '/pages/notice/projectTeam/interactiveQuestionAndAnswer/interactiveQuestionAndAnswer',
    },
    {
        type: '06',
        path: '/pages/notice/projectNotice/projectNotice',
    },
    {
        type: '07',
        path: '/functionPage/pages/experienceDetail/experienceDetail',
    },
];
Component({
    options: {
        multipleSlots: true, // 在组件定义时的选项中启用多slot支持
    },
    /**
     * 组件的属性列表
     */
    properties: {
        avatar: {
            type: String,
            value: 'https://static.map8.com/sp/20200327/0_154226589822.jpg',
        },
        name: {
            type: String,
            value: '张三',
        },
        time: {
            type: String,
            value: '12分钟前',
        },
        // 文章正文
        bodyContent: {
            type: String,
        },
        // 答案正文
        content: {
            type: String,
        },
        // 通告或者问题
        main: {
            type: String,
        },
        //已读未读标记
        readflg: {
            type: String,
        },
        type: {
            type: String,
        },
        pctype: {
            type: String,
        },
        originid: {
            type: String,
        },
        pic: {
            type: String,
        },
    },

    /**
     * 组件的初始数据
     */
    data: {},

    /**
     * 组件的方法列表
     */
    methods: {
        changeNav: throttle(
            function () {
                let nav = this.getNewsPage(pathArray, 'type');
                console.log(nav);
                if (nav) {
                    wx.navigateTo({
                        url: `${nav}`,
                    });
                }
            },
            200,
            {
                trailing: false,
            }
        ),

        getNewsPage(arr, typeName) {
            let pathIndex = arr.findIndex(
                (item) => item.type === this.data[typeName]
            );
            if (pathIndex > -1) {
                if (arr[pathIndex].path) {
                    if (arr[pathIndex].path.indexOf('?') > -1) {
                        return `${arr[pathIndex].path}&id=${this.data.originid}`;
                    } else {
                        return `${arr[pathIndex].path}?id=${this.data.originid}`;
                    }
                } else {
                    return this.getNewsPage(arr[pathIndex].childen, 'pctype');
                }
            } else {
                return;
            }
        },
    },
});
